package com.example.newsapplication;

import android.app.Application;
import android.content.SharedPreferences;
import android.util.Log;

import skin.support.SkinCompatManager;
import skin.support.app.SkinAppCompatViewInflater;

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        SkinCompatManager.withoutActivity(this)
                .addInflater(new SkinAppCompatViewInflater())           // 基础控件换肤初始化
                .setSkinStatusBarColorEnable(false)                     // 关闭状态栏换肤，默认打开[可选]
                .setSkinWindowBackgroundEnable(false)                   // 关闭windowBackground换肤，默认打开[可选]
                .loadSkin();
        SharedPreferences sp = getSharedPreferences("sp_ttit", MODE_PRIVATE);
        String skin = sp.getString("skin", "");
        try {
            SkinCompatManager skinCompatManager = SkinCompatManager.getInstance();
            if (skinCompatManager != null) {
                if (skin.equals("night")) {
                    skinCompatManager.loadSkin("night", SkinCompatManager.SKIN_LOADER_STRATEGY_BUILD_IN); // 后缀加载
                } else {
                    skinCompatManager.restoreDefaultTheme();
                }
            } else {
                // 处理 SkinCompatManager 为 null 的情况
                Log.e("MyApp", "SkinCompatManager is null");
            }
        } catch (Exception e) {
            // 捕获并记录异常
            Log.e("MyApp", "Error restoring default theme: " + e.getMessage(), e);
        }


    }
}
